<?php
/**
 * @copyright meila.com
 * @author wangtao5@
 * @name 删除宝贝接口
 * @param 
 *         $nick = 作用
 * 
 * 
 */
include('../../__global.php');
class aj_delUserfeed extends ml_controller 
{
    private $rid;
    private $arrAlert = array(
        'rid' => 'rid'
    );

    function initParam()
    {
        /**
         * @todo get post
         */
        $this->rid = $this->input('rid', 'P', '');
    }
    /**
     * @develop_template
     * 检查参数合法性
     */
    function checkParam()
    {
        $this->check_referer();
        if(empty($this->rid)){
            $this->api_output(ML_RCODE_PARAM , '', $this->arrAlert['rid']);
        }
        if(!$this->check_permission(ML_PERMISSION_LOGIN_ONLY)) {
            return $this->api_output(ML_RCODE_NOLOGIN);
        }
        else if(!$this->check_permission(ML_PERMISSION_LOGIN_CANWRITE)) {
            return $this->api_output(ML_RCODE_NOACTIVE);
        }
        if(ml_tool_resid::resid2uid($this->rid)!=$this->__visitor['uid']){
            $this->api_output(ML_RCODE_PARAM);
        }

    }
    /**
     * @develop_template
     * 核心业务逻辑
     */
    function main()
    {
        
        //删除feed表中数据
        $oUserfeed = new ml_model_dbUserfeed();
        $rDb_userfeed = $oUserfeed->del_contentByRid($this->rid);
        //获取content_rid
        $oUserfeed->getContentRid_by_rid($this->rid);
        $data=$oUserfeed->get_data();
        
        $oRedis = new ml_model_rdsCount();
        $oRedis->decrUserfeedcnt($this->__visitor['uid']);
        
        //删除content表中数据
        
        //可删类型
        $typeArr=array( 
            ML_FEED_TYPE_PUB_DOTEY,
            ML_FEED_TYPE_PUB_PIC,     
            ML_FEED_TYPE_PUB_SHORT,
            ML_FEED_TYPE_MOD_DEC,        
            ML_FEED_TYPE_MOD_TAG,
        );
        if( in_array($data['type'],$typeArr) && ml_tool_resid::resid2uid($data['content_rid'])!=$this->__visitor['uid']){
            $oContent = new ml_model_dbContent();
            $rDb_content = $oContent->del_contentByRid($data['content_rid']);
            
            ml_tool_sendMq::search_content('A',$data['content_rid']);
            ml_tool_sendMq::del_atme_in_content($data['content_rid']);
            $oRedis->decrUserContentcnt($this->__visitor['uid']);
            ml_tool_sendMq::del_like_feed($data['content_rid']);
            ml_tool_actionlog::del_content($this->__visitor['uid'] , $data['content_rid']);
        }
        else 
        {
            ml_tool_sendMq::del_atme_in_content($this->rid);
            ml_tool_sendMq::del_like_feed($this->rid);
        }
        
        if($rDb_userfeed){
            $this->api_output(ML_RCODE_SUCC);
        }else{
            $this->api_output(ML_RCODE_BUSY);
        }
    }
}

new aj_delUserfeed();
